package net.phoenix.repository.query.qom2;

import javax.jcr.query.qom.Column;

/**
 * <code>ColumnImpl</code>...
 */
public class ColumnImpl extends AbstractQOMNode implements Column {

	/**
	 * Empty <code>ColumnImpl</code> array.
	 */
	public static final ColumnImpl[] EMPTY_ARRAY = new ColumnImpl[0];

	/**
	 * The name of the selector.
	 */
	private final String selectorName;

	/**
	 * The name of the property.
	 */
	private final String propertyName;

	/**
	 * The name of the column.
	 */
	private final String columnName;

	ColumnImpl(NamePathResolver resolver, String selectorName, String propertyName, String columnName) {
		super(resolver);
		this.selectorName = selectorName;
		this.propertyName = propertyName;
		this.columnName = columnName;
	}

	// ---------------------------< Column
	// >-------------------------------------

	/**
	 * Gets the name of the selector.
	 * 
	 * @return the selector name; non-null
	 */
	public String getSelectorName() {
		return (selectorName);
	}

	/**
	 * Gets the name of the property.
	 * 
	 * @return the property name, or null to include a column for each
	 *         single-value non-residual property of the selector's node type
	 */
	public String getPropertyName() {
		return (propertyName);
	}

	/**
	 * Gets the column name.
	 * <p/>
	 * 
	 * @return the column name; must be null if <code>getPropertyName</code> is
	 *         null and non-null otherwise
	 */
	public String getColumnName() {
		return columnName;
	}

	// ------------------------< AbstractQOMNode
	// >-------------------------------

	/**
	 * Accepts a <code>visitor</code> and calls the appropriate visit method
	 * depending on the type of this QOM node.
	 * 
	 * @param visitor
	 *            the visitor.
	 */
	public Object accept(QOMTreeVisitor visitor, Object data) throws Exception {
		return visitor.visit(this, data);
	}

	// ------------------------< Object
	// >----------------------------------------

	public String toString() {
		if (propertyName != null) {
			return getSelectorName() + "." + getPropertyName() + "  " + getColumnName();
		} else {
			return getSelectorName() + ".*";
		}
	}

}
